package com.example.learn.hwod;

import java.util.Collections;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.TreeSet;

public class _08英文输入法 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String pre = sc.nextLine();
        System.out.println(getResult(str,pre));
    }

    private static String getResult(String str, String pre) {

        String[] split = str.split("[^a-zA-Z]");
        TreeSet<String> cache = new TreeSet<>();
        Collections.addAll(cache,split);
        StringJoiner joiner = new StringJoiner(" ");
        cache.stream().filter(s->s.startsWith(pre)).forEach(s->joiner.add(s));
        String ans = joiner.toString();
        if (ans.length()>0) {
            return ans;
        }else{
            return pre;
        }
    }
}
